{* $Id$ *}
{include_core file="admin/lib/header.html" title="播放单管理"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">播放单管理<span>{if $info}编辑{else}添加{/if}播放单</span></h2>
  <a href="{AnUrl('play_list/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回播放单列表</a>
</div>

<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('play_list/admin/save')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$info.id}">
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">播放单名称：</label></th>
        <td>
          <input name="info[title]" style="width:490px;" value="{$info.title}" type="text" class="add-f-ipt1 js_title">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>播放单名会显示在相应内容的标题位置，最多输入 <span style="color:red;">30</span> 字，还可输入 <span class="js_titleNum" style="color:red;">30</span> 字</div>
        </td>
      </tr>
      <tr class='js_location'>
        <th><label for="" class="add-f-label">播放地址：</label></th>
        <td>
        {$province_list = material_helper::get_province(0, 1)}{* 省列表 *}
          <select class="add-f-slt1 js_province" name="info[province]">
            <option value="0" code='0'>全国</option>
            {foreach $province_list as $k=>$v}
                <option value="{$v.area}" {if $info.province == $v.area}selected{/if} code="{$v.id}">{$v.area}</option>
            {/foreach}
          </select>
          <select class="add-f-slt1 js_city" name="info[city]">
            {if $info.city}
              <option value="{$info.city}">{$info.city}</option>
            {else}
              <option value="0">全国</option>
            {/if}
          </select>
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>素材播放的地址</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">开始播放时间：</label></th>
        <td>
          <input name="info[start_time]" style="width:490px;" value="{$info.start_time}" type="text" class="add-f-ipt1 startDate" id="startDate"><!-- id="startDate" -->
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>什么时间开始播放 <span style='color:red'>例如：2015-11-15</span></div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">结束播放时间：</label></th>
        <td>
          <input name="info[stop_time]" style="width:490px;" value="{$info.stop_time}" type="text" class="add-f-ipt1 stopDate" id="stopDate"><!-- id="stopDate" -->
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>什么时间停止播放 <span style='color:red'>例如：2015-11-16</span></div>
        </td>
      </tr>
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>

{load_js file="uploadify/jquery.uploadify.min.js"}
<script>
function setNum(thisClass, maxNum) {
  var presentNum = getFontNum($('.'+thisClass).val());
  var remainNum  = maxNum - presentNum;
  $('.'+thisClass+'Num').text(remainNum);
}

$(function(){
  // 初始化剩余字数
  setNum('js_title', 30);

  $('.js_title').keyup(function(){
    setNum('js_title', 30);
  });

  // 城市联动
  $('.js_province').change(function(){
    var thisObj = $(this);
    var code = thisObj.find('option:selected').attr('code');
    if (code == 0) {
        $('.js_city').html('<option value="0">全国</option>');
        return ;
    }
    //发送ajax
    $.ajax({
      url : 'material/admin/get_city?code='+code,
      success : function(city_list){
        var html = '<option value="0">请选择市</option>';
        for (var i in city_list) {
          html += '<option value="'+city_list[i]['area']+'">'+city_list[i]['area']+'</option>';
          $('.js_city').html(html);
        }
      },
      type : 'get',
      dataType : 'json',
      async : false,
    });
  });

  // 提交验证
  $('.js_submit').click(function(){
    var thisObj   = $(this);
    var title = $.trim($('.js_title').val());
    var nationwide = $('.js_nationwide').val();
    var stop_time = $.trim($('.js_time').val());
    var startDate = $.trim($('.startDate').val());
    var stopDate  = $.trim($('.stopDate').val());

    if (!title) {
        showMsg('请输入播放单名称');
        return false;
    }
    if (title.length > 30) {
        showMsg('您输入的播放单名过长');
        return false;
    }

    if (!startDate || !stopDate) {
        showMsg('请选择开始时间和结束时间');
        return false;
    }

    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return false;
    }
  });
});
</script>
{include_core file="admin/lib/footer.html"}